﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class News_AllNews : System.Web.UI.Page
{
    public SecurityLib.Sec_AES _ps = new SecurityLib.Sec_AES();
    private void BindGrid()
    {
        _dbDataContext _db = new _dbDataContext();
        var val = from p in _db.tblNews
                  where p.DonViNhan.Contains(MemberShip_ASP.GetMaDonViFromUserName(this.Page.User.Identity.Name)) orderby p.ID descending
                  select new MemberShip_ASP.ItemNews
                  {
                      ID = p.ID,
                      Title = p.TieuDe.Trim(),
                      NguoiDang = p.tblAcount.TenHienThi.Trim(),
                      NgayDang = string.Format("{0:dd/MM/yyyy}", p.NgayDang),
                      Loai = p.Loai
                  };
        grid_news.DataSource = val.ToList();
        grid_news.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    protected void grid_news_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i <= grid_news.Rows.Count - 1; i++)
        {
            Label lblparent = (Label)grid_news.Rows[i].FindControl("lblloai");

            if (lblparent.Text == "1")
            {
                grid_news.Rows[i].Cells[3].Text = "<button class='btn btn-circle btn-success show-tooltip' data-original-title='Tin tức'><i class='icon-file-text-alt'></i></button>";
            }
            else if (lblparent.Text == "2")
            {
                grid_news.Rows[i].Cells[3].Text = "<button class='btn btn-circle  btn-primary show-tooltip' data-original-title='Thông báo'><i class= 'icon-envelope-alt'></i></button>";
            }
        }
    }
    protected void btn_LocXemTatCa_Click(object sender, EventArgs e)
    {
        BindGrid();
    }
    protected void linkDoanVien_Click(object sender, EventArgs e)
    {
        _dbDataContext _db = new _dbDataContext();
        var val = from p in _db.tblNews
                  where p.DonViNhan.Contains(MemberShip_ASP.GetMaDonViFromUserName(this.Page.User.Identity.Name)) && p.Loai==1
                  orderby p.ID descending
                  select new MemberShip_ASP.ItemNews
                  {
                      ID = p.ID,
                      Title = p.TieuDe.Trim(),
                      NguoiDang = p.tblAcount.TenHienThi.Trim(),
                      NgayDang = string.Format("{0:dd/MM/yyyy}", p.NgayDang),
                      Loai = p.Loai
                  };
        grid_news.DataSource = val.ToList();
        grid_news.DataBind();
    }
    protected void linkDoanVienTruongThanh_Click(object sender, EventArgs e)
    {
        _dbDataContext _db = new _dbDataContext();
        var val = from p in _db.tblNews
                  where p.DonViNhan.Contains(MemberShip_ASP.GetMaDonViFromUserName(this.Page.User.Identity.Name)) && p.Loai==2
                  orderby p.ID descending
                  select new MemberShip_ASP.ItemNews
                  {
                      ID = p.ID,
                      Title = p.TieuDe.Trim(),
                      NguoiDang = p.tblAcount.TenHienThi.Trim(),
                      NgayDang = string.Format("{0:dd/MM/yyyy}", p.NgayDang),
                      Loai = p.Loai
                  };
        grid_news.DataSource = val.ToList();
        grid_news.DataBind();
    }
}